﻿using NetTaste;
using SimpleInOutControl.Common;
using SimpleInOutControl.DBModels;

namespace SimpleInOutControl.Services
{
    public class DeviceInfoService: BaseService
    {
        public bool AddData(DeviceInfo dto)
        {
            using (var client = DataBaseHelper.GetSqlSugarClient())
            {
                var count = client.Insertable(dto).ExecuteCommand(); ;
                return count > 0;
            }
        }
        public bool UpdateData(DeviceInfo dto)
        {
            using (var client = DataBaseHelper.GetSqlSugarClient())
            {
                var count = client.Updateable(dto).IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue: true).ExecuteCommand();
                return count > 0;
            }
        }

        public bool DeleteData(int id)
        {
            using (var client = DataBaseHelper.GetSqlSugarClient())
            {
                var obj = client.Queryable<DeviceInfo>().Where(u => u.ID == id).First();
                if (obj == null)
                {
                    return false;
                }
                var count = client.Deleteable(obj).ExecuteCommand();
                return count > 0;
            }
        }

        public DeviceInfo GetData(int id)
        {
            using (var client = DataBaseHelper.GetSqlSugarClient())
            {
                var data = client.Queryable<DeviceInfo>().Where(u=>u.ID==id).First();
                return data;
            }
        }

        public List<DeviceInfo> GetPageData(PagingRequest<UserInfo> dto)
        {
            using (var client = DataBaseHelper.GetSqlSugarClient())
            {
                var datas = client.Queryable<DeviceInfo>().ToList();
                return datas;
            }
        }
    }
}
